package o;

import java.nio.ShortBuffer;
import java.util.Arrays;

final class acs {
    private final int ʻ;
    private int ʻॱ;
    private final short[] ʼ = new short[this.ᐝ];
    private int ʼॱ;
    private final int ʽ;
    private int ˈ;
    private final int ˊ;
    private short[] ˊॱ;
    private final float ˋ;
    private int ˋॱ;
    private final float ˎ;
    private final float ˏ;
    private int ˏॱ;
    private short[] ͺ;
    private final int ॱ;
    private int ॱˊ;
    private int ॱˋ;
    private int ॱˎ;
    private short[] ॱॱ;
    private int ॱᐝ;
    private final int ᐝ = (this.ʻ * 2);
    private int ᐝॱ;

    public acs(int i, int i2, float f, float f2, int i3) {
        this.ˊ = i;
        this.ॱ = i2;
        this.ˏ = f;
        this.ˎ = f2;
        this.ˋ = ((float) i) / ((float) i3);
        this.ʽ = i / 400;
        this.ʻ = i / 65;
        this.ॱॱ = new short[(this.ᐝ * i2)];
        this.ˊॱ = new short[(this.ᐝ * i2)];
        this.ͺ = new short[(this.ᐝ * i2)];
    }

    public void ॱ(ShortBuffer shortBuffer) {
        int remaining = shortBuffer.remaining() / this.ॱ;
        int i = (this.ॱ * remaining) * 2;
        this.ॱॱ = ˊ(this.ॱॱ, this.ॱˊ, remaining);
        shortBuffer.get(this.ॱॱ, this.ॱˊ * this.ॱ, i / 2);
        this.ॱˊ = remaining + this.ॱˊ;
        ॱ();
    }

    public void ˎ(ShortBuffer shortBuffer) {
        int min = Math.min(shortBuffer.remaining() / this.ॱ, this.ˋॱ);
        shortBuffer.put(this.ˊॱ, 0, this.ॱ * min);
        this.ˋॱ -= min;
        System.arraycopy(this.ˊॱ, min * this.ॱ, this.ˊॱ, 0, this.ˋॱ * this.ॱ);
    }

    public void ˏ() {
        int i = this.ॱˊ;
        float f = this.ˋ * this.ˎ;
        int i2 = this.ˋॱ + ((int) ((((((float) i) / (this.ˏ / this.ˎ)) + ((float) this.ˏॱ)) / f) + 0.5f));
        this.ॱॱ = ˊ(this.ॱॱ, this.ॱˊ, (this.ᐝ * 2) + i);
        for (int i3 = 0; i3 < (this.ᐝ * 2) * this.ॱ; i3++) {
            this.ॱॱ[(this.ॱ * i) + i3] = (short) 0;
        }
        this.ॱˊ += this.ᐝ * 2;
        ॱ();
        if (this.ˋॱ > i2) {
            this.ˋॱ = i2;
        }
        this.ॱˊ = 0;
        this.ᐝॱ = 0;
        this.ˏॱ = 0;
    }

    public void ˎ() {
        this.ॱˊ = 0;
        this.ˋॱ = 0;
        this.ˏॱ = 0;
        this.ॱˋ = 0;
        this.ॱˎ = 0;
        this.ᐝॱ = 0;
        this.ॱᐝ = 0;
        this.ʻॱ = 0;
        this.ˈ = 0;
        this.ʼॱ = 0;
    }

    public int ˋ() {
        return this.ˋॱ;
    }

    private short[] ˊ(short[] sArr, int i, int i2) {
        int length = sArr.length / this.ॱ;
        return i + i2 <= length ? sArr : Arrays.copyOf(sArr, (((length * 3) / 2) + i2) * this.ॱ);
    }

    private void ˎ(int i) {
        int i2 = this.ॱˊ - i;
        System.arraycopy(this.ॱॱ, this.ॱ * i, this.ॱॱ, 0, this.ॱ * i2);
        this.ॱˊ = i2;
    }

    private void ॱ(short[] sArr, int i, int i2) {
        this.ˊॱ = ˊ(this.ˊॱ, this.ˋॱ, i2);
        System.arraycopy(sArr, this.ॱ * i, this.ˊॱ, this.ˋॱ * this.ॱ, this.ॱ * i2);
        this.ˋॱ += i2;
    }

    private int ॱ(int i) {
        int min = Math.min(this.ᐝ, this.ᐝॱ);
        ॱ(this.ॱॱ, i, min);
        this.ᐝॱ -= min;
        return min;
    }

    private void ˎ(short[] sArr, int i, int i2) {
        int i3 = this.ᐝ / i2;
        int i4 = this.ॱ * i2;
        int i5 = i * this.ॱ;
        for (int i6 = 0; i6 < i3; i6++) {
            int i7 = 0;
            for (int i8 = 0; i8 < i4; i8++) {
                i7 += sArr[((i6 * i4) + i5) + i8];
            }
            this.ʼ[i6] = (short) (i7 / i4);
        }
    }

    private int ˋ(short[] sArr, int i, int i2, int i3) {
        int i4 = 255;
        int i5 = 1;
        int i6 = i * this.ॱ;
        int i7 = i2;
        int i8 = 0;
        int i9 = 0;
        while (i7 <= i3) {
            int i10 = 0;
            int i11 = 0;
            while (i10 < i7) {
                int abs = Math.abs(sArr[i6 + i10] - sArr[(i6 + i7) + i10]) + i11;
                i10++;
                i11 = abs;
            }
            if (i11 * i9 < i5 * i7) {
                i5 = i11;
                i9 = i7;
            }
            if (i11 * i4 > i8 * i7) {
                i8 = i7;
            } else {
                i11 = i8;
                i8 = i4;
            }
            i7++;
            i4 = i8;
            i8 = i11;
        }
        this.ˈ = i5 / i9;
        this.ʼॱ = i8 / i4;
        return i9;
    }

    private boolean ॱ(int i, int i2) {
        if (i == 0 || this.ॱᐝ == 0 || i2 > i * 3 || i * 2 <= this.ʻॱ * 3) {
            return false;
        }
        return true;
    }

    private int ˏ(short[] sArr, int i) {
        int i2;
        int i3 = this.ˊ > 4000 ? this.ˊ / 4000 : 1;
        if (this.ॱ == 1 && i3 == 1) {
            i3 = ˋ(sArr, i, this.ʽ, this.ʻ);
        } else {
            ˎ(sArr, i, i3);
            int ˋ = ˋ(this.ʼ, 0, this.ʽ / i3, this.ʻ / i3);
            if (i3 != 1) {
                int i4 = ˋ * i3;
                ˋ = i4 - (i3 * 4);
                i4 += i3 * 4;
                if (ˋ < this.ʽ) {
                    i3 = this.ʽ;
                } else {
                    i3 = ˋ;
                }
                if (i4 > this.ʻ) {
                    ˋ = this.ʻ;
                } else {
                    ˋ = i4;
                }
                if (this.ॱ == 1) {
                    i3 = ˋ(sArr, i, i3, ˋ);
                } else {
                    ˎ(sArr, i, 1);
                    i3 = ˋ(this.ʼ, 0, i3, ˋ);
                }
            } else {
                i3 = ˋ;
            }
        }
        if (ॱ(this.ˈ, this.ʼॱ)) {
            i2 = this.ॱᐝ;
        } else {
            i2 = i3;
        }
        this.ʻॱ = this.ˈ;
        this.ॱᐝ = i3;
        return i2;
    }

    private void ˊ(int i) {
        int i2 = this.ˋॱ - i;
        this.ͺ = ˊ(this.ͺ, this.ˏॱ, i2);
        System.arraycopy(this.ˊॱ, this.ॱ * i, this.ͺ, this.ˏॱ * this.ॱ, this.ॱ * i2);
        this.ˋॱ = i;
        this.ˏॱ = i2 + this.ˏॱ;
    }

    private void ˋ(int i) {
        if (i != 0) {
            System.arraycopy(this.ͺ, this.ॱ * i, this.ͺ, 0, (this.ˏॱ - i) * this.ॱ);
            this.ˏॱ -= i;
        }
    }

    private short ˊ(short[] sArr, int i, int i2, int i3) {
        int i4 = (this.ॱˋ + 1) * i3;
        int i5 = i4 - (this.ॱˎ * i2);
        int i6 = i4 - (this.ॱˋ * i3);
        return (short) (((sArr[i] * i5) + (sArr[this.ॱ + i] * (i6 - i5))) / i6);
    }

    private void ˊ(float f, int i) {
        if (this.ˋॱ != i) {
            int i2 = (int) (((float) this.ˊ) / f);
            int i3 = this.ˊ;
            int i4 = i2;
            while (true) {
                if (i4 <= 16384 && i3 <= 16384) {
                    break;
                }
                i3 /= 2;
                i4 /= 2;
            }
            ˊ(i);
            for (int i5 = 0; i5 < this.ˏॱ - 1; i5++) {
                while ((this.ॱˋ + 1) * i4 > this.ॱˎ * i3) {
                    this.ˊॱ = ˊ(this.ˊॱ, this.ˋॱ, 1);
                    for (i2 = 0; i2 < this.ॱ; i2++) {
                        this.ˊॱ[(this.ˋॱ * this.ॱ) + i2] = ˊ(this.ͺ, (this.ॱ * i5) + i2, i3, i4);
                    }
                    this.ॱˎ++;
                    this.ˋॱ++;
                }
                this.ॱˋ++;
                if (this.ॱˋ == i3) {
                    this.ॱˋ = 0;
                    amm.ˏ(this.ॱˎ == i4);
                    this.ॱˎ = 0;
                }
            }
            ˋ(this.ˏॱ - 1);
        }
    }

    private int ˏ(short[] sArr, int i, float f, int i2) {
        int i3;
        if (f >= 2.0f) {
            i3 = (int) (((float) i2) / (f - 1.0f));
        } else {
            this.ᐝॱ = (int) ((((float) i2) * (2.0f - f)) / (f - 1.0f));
            i3 = i2;
        }
        this.ˊॱ = ˊ(this.ˊॱ, this.ˋॱ, i3);
        ˋ(i3, this.ॱ, this.ˊॱ, this.ˋॱ, sArr, i, sArr, i + i2);
        this.ˋॱ += i3;
        return i3;
    }

    private int ˊ(short[] sArr, int i, float f, int i2) {
        int i3;
        if (f < 0.5f) {
            i3 = (int) ((((float) i2) * f) / (1.0f - f));
        } else {
            this.ᐝॱ = (int) ((((float) i2) * ((2.0f * f) - 1.0f)) / (1.0f - f));
            i3 = i2;
        }
        this.ˊॱ = ˊ(this.ˊॱ, this.ˋॱ, i2 + i3);
        System.arraycopy(sArr, this.ॱ * i, this.ˊॱ, this.ˋॱ * this.ॱ, this.ॱ * i2);
        ˋ(i3, this.ॱ, this.ˊॱ, this.ˋॱ + i2, sArr, i + i2, sArr, i);
        this.ˋॱ += i2 + i3;
        return i3;
    }

    private void ˊ(float f) {
        if (this.ॱˊ >= this.ᐝ) {
            int i = this.ॱˊ;
            int i2 = 0;
            do {
                if (this.ᐝॱ > 0) {
                    i2 += ॱ(i2);
                } else {
                    int ˏ = ˏ(this.ॱॱ, i2);
                    if (((double) f) > 1.0d) {
                        i2 += ˏ + ˏ(this.ॱॱ, i2, f, ˏ);
                    } else {
                        i2 += ˊ(this.ॱॱ, i2, f, ˏ);
                    }
                }
            } while (this.ᐝ + i2 <= i);
            ˎ(i2);
        }
    }

    private void ॱ() {
        int i = this.ˋॱ;
        float f = this.ˏ / this.ˎ;
        float f2 = this.ˋ * this.ˎ;
        if (((double) f) > 1.00001d || ((double) f) < 0.99999d) {
            ˊ(f);
        } else {
            ॱ(this.ॱॱ, 0, this.ॱˊ);
            this.ॱˊ = 0;
        }
        if (f2 != 1.0f) {
            ˊ(f2, i);
        }
    }

    private static void ˋ(int i, int i2, short[] sArr, int i3, short[] sArr2, int i4, short[] sArr3, int i5) {
        for (int i6 = 0; i6 < i2; i6++) {
            int i7 = (i3 * i2) + i6;
            int i8 = (i5 * i2) + i6;
            int i9 = (i4 * i2) + i6;
            for (int i10 = 0; i10 < i; i10++) {
                sArr[i7] = (short) (((sArr2[i9] * (i - i10)) + (sArr3[i8] * i10)) / i);
                i7 += i2;
                i9 += i2;
                i8 += i2;
            }
        }
    }
}
